package net.aias.springaichat.adapter.openapi;

import lombok.extern.slf4j.Slf4j;
import net.aias.springaichat.business.ai.embedding.EmbeddingService;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Auther: cheng.tang
 * @Date: 2025/5/13
 * @Description: spring-ai-chat
 */
@RestController
@Slf4j
public class EmbeddingController {

    private final EmbeddingService embeddingService;

    @Autowired
    public EmbeddingController(EmbeddingService embeddingService) {
        this.embeddingService = embeddingService;
    }

    @GetMapping("/ai/embedding")
    public Map<String, Object> embed(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        EmbeddingResponse embeddingResponse = embeddingService.embedText(message);
        return Map.of("embedding", embeddingResponse.getResult());
    }


}
